package design.simdi.code.final_paper.site.application;

import org.apache.wicket.Page;
import org.apache.wicket.RedirectToUrlException;
import org.apache.wicket.Response;
import org.apache.wicket.authorization.UnauthorizedInstantiationException;
import org.apache.wicket.protocol.http.PageExpiredException;
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebRequestCycle;

import design.simdi.code.final_paper.site.pages.MyErrorPage;

/**
 * 
 * @author Marius Dumitriu - (Jun 27, 2010 - 1:39:55 AM)
 * 
 */
public class MyRequestCycle extends WebRequestCycle {

	public MyRequestCycle(WebApplication application, WebRequest request, Response response) {
		super(application, request, response);

	}

	public final Page onRuntimeException(final Page cause, final RuntimeException e) {
		// Daca incearca sa intre pe o pagina care necesita autentificare ..
		// trimit la pagina de login
		if (e instanceof UnauthorizedInstantiationException)
			throw new RedirectToUrlException("/login");
		// Daca sesiunea a expirat .. trimit la pagina de home
		if (e instanceof PageExpiredException)
			throw new RedirectToUrlException("/home");

		return new MyErrorPage(e);
	}

}
